﻿using B.S.Data.MES.API.Applications.QualityManagement.ExamineTaskCommand.Commands;
using B.S.Domain.BasicData.QualityManagement;
using B.S.Infratrctrue;
using B.S.Requst;
using FluentAssertions.Events;
using MediatR;
using Yitter.IdGenerator;

namespace B.S.Data.MES.API.Applications.QualityManagement.ExamineTaskCommand.CommandHandlers
{
    public class CreateExaminetaskCommandHandler : IRequestHandler<CreateExaminetaskCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<ExamineTask> _examinetaskRepository;
        public CreateExaminetaskCommandHandler(IBaseRepository<ExamineTask> examinetaskRepository)
        {
            _examinetaskRepository = examinetaskRepository;
        }
        public async Task<APIRequst<int>> Handle(CreateExaminetaskCommand request, CancellationToken cancellationToken)
        {
            ExamineTask task = new ExamineTask();
            task.TaskNo = YitIdHelper.NextId().ToString();
            task.QualityType = request.QualityType;
            task.QualityProposal = request.QualityProposal;
            task.TicketCode = request.TicketCode;
            task.PermissionRoleId = request.PermissionRoleId;

            await _examinetaskRepository.Add(task);
            return await Task.FromResult(new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString()
            });
        }
    }
}
